/*
 * testUTF8Reader.cpp
 *
 *  Created on: 2011-9-24
 *      Author: 胡剑青
 */

#include "util.h"
#include <cstdlib>
#include <cstdio>
#include <cwchar>
#include <clocale>

int main()
{
	try {
		//初始化
		zach::util::UTF8Reader reader;
		reader.init( "test\\utf8.txt" );

		//接收字符串
		wchar_t buf[256];
		int len = 0;

		//循环读入
		while ( !reader.isEnd() ) {
			//读
			reader.readChar();
			//位置
			zach::TextPosition pos = reader.position();
			printf( "%d, %d\n", pos.row, pos.col );
			//填入
			buf[len] = reader.lastRead();
			len++;
		}

		//打印（设置local后能打印出中文字符）
		setlocale( LC_ALL, "" );
		buf[len] = 0;
		wprintf( buf );
	}
	catch ( zach::Error& e ) {
		printf( "Error: %s\n", e.message().c_str() );
	}

	return 0;
}
